home *** CD-ROM | disk | FTP | other *** search
/ 10,000 Great Games / 10,000 Great Games.iso / Product / 66 / data1.cab / Source_Files / Src / Gameloop.cpp < prev    next >
C/C++ Source or Header  |  2000-01-16  |  2KB  |  122 lines

  1. #include "stdafx.h"
  2.  
  3. int end_game = TRUE;
  4.  
  5. void game_loop()
  6. {
  7.     MSG msg;
  8.  
  9.     // We're entering the game loop
  10.  
  11.     end_game = FALSE;
  12.  
  13.     // Acquire the mouse to rid windows of message pump
  14.  
  15.     init_mouse();
  16.     
  17.     // Delete editables
  18.  
  19.     cEditable::delete_editables();
  20.  
  21.     // Create disaster
  22.     
  23.     cDisaster::make();
  24.     
  25.     // Assign players
  26.     
  27.     cPlayer::make();
  28.  
  29.     // Play some music
  30.  
  31.     play_music("MAIN", TRUE);
  32.  
  33.     // Write the first frame
  34.  
  35.     write_frame();
  36.  
  37.     // Unpause game
  38.     
  39.     cTimer::unpause();
  40.     
  41.     // Enter game loop
  42.  
  43.     while (!end_game)
  44.     {
  45.         if (PeekMessage(&msg, mainwindowhandle, 0, 0, PM_REMOVE))
  46.             switch (msg.message)
  47.             {
  48.             case WM_KEYDOWN:
  49.                 switch (msg.wParam)
  50.                 {
  51.                 case VK_ESCAPE:
  52.                     end_game = TRUE;
  53.                     break;
  54.                     
  55.                 case VK_PAUSE:
  56.                     cTimer::togglepause();
  57.                     break;
  58.  
  59.                 case VK_F12:
  60.                     make_screenshot();
  61.                     break;
  62.                     
  63.                 default:
  64.                     cTimer::unpause();
  65.                     break;
  66.                 }                
  67.  
  68.             case MM_MCINOTIFY:
  69.                 if(msg.wParam == MCI_NOTIFY_SUCCESSFUL)
  70.                     replay_music();
  71.                 break;
  72.  
  73.             case WM_PAINT:
  74.                 if (inawin)
  75.                     DispatchMessage(&msg);
  76.                 break;
  77.             }
  78.             
  79.         // Reacquire mouse if lost
  80.  
  81.         acquire_mouse();
  82.  
  83.         // Update frame
  84.  
  85.         if (!cTimer::is_paused())
  86.         {
  87.             // Make sounds
  88.             
  89.             ambient_sounds();        
  90.  
  91.             // Scroll the background buffer
  92.             
  93.             do_scrolling();
  94.             
  95.             // Control objects
  96.             
  97.             control_level();
  98.  
  99.             // Check end level
  100.  
  101.             if (first_at_end != 0)
  102.             {
  103.                 bubbles->delete_list();
  104.                 players->delete_list();
  105.                 scores->delete_list();
  106.             }
  107.  
  108.             // Write a frame and show it
  109.  
  110.             write_frame();
  111.         }
  112.     }
  113.  
  114.     // Pause the timer
  115.  
  116.     cTimer::pause();
  117.  
  118.     // Unaquire the mouse
  119.  
  120.     deinit_mouse();
  121. }
  122.